/*
 * @Author: your name
 * @Date: 2020-05-22 16:13:52
 * @LastEditTime: 2020-10-30 10:30:16
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /yigo/src/Pages/SettingScreen.js
 */ 
import React, { Component } from 'react'
import { View, Text, StyleSheet } from 'react-native'
import { connect } from 'react-redux'
import Button from 'apsl-react-native-button'
import Storage from '../Utils/AsyncStorage'

class SettingScreen extends Component {

    constructor(props) {
        super(props)
        this.state = {
          address:API_ROOT
        };
      }

    outLogin = () => {
        Storage.delete("token").then((error) => {
            if (!error) {      
                global.userInfo = null;        
                this.props.refreshToken({token:''})
            }
        })
    }
    
    renderCell() {
        if (__DEV__) {
            return <Text>开发环境</Text>
        } else {
            return <Text>生产环境</Text>
        }
    }

    
    render() {
        let userType = userInfo.userType === 0 ? "用户" :
        userInfo.userType === 1 ? "商家" :
        userInfo.userType === 2 ? "骑手" : '未知'

        return (
            <View style={{flex:1,justifyContent:"space-around", alignItems:'center',paddingTop:60}}>
                <View style={{justifyContent:'space-around',alignItems:'center'}}>
                    <Text style={{marginBottom:50}}>{`当前登录账号:${userInfo.phone}${userType}`}</Text>
                    {this.renderCell()}
                </View>
                
                <Button style={styles.buttonStyle} textStyle={{fontSize: 18,color: 'white'}} onPress={this.outLogin}>退出登录</Button>
            </View>
        )
    }
}

const styles = StyleSheet.create({
   
    buttonStyle: {
      height: 44,
      flexDirection: 'row',
      alignItems: 'center',
      borderWidth: 0,
      borderRadius: 22,
      marginBottom: 30,
      marginTop: 440,
      alignSelf: 'stretch',
      justifyContent: 'center',
      backgroundColor: '#F66701',
      margin: 20,
    }
});
const mapStateToProps = (state) => ({
    
    
})

const mapDispatchToProps = (dispatch, ownProps) => {  
    return {
      refreshToken:(paramter) => dispatch({paramter,type:'RefreshToken'})
    }
  }

export default connect(mapStateToProps, mapDispatchToProps)(SettingScreen)

